package blank;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Set;

public class JavaSource implements Serializable {
	
	/**
	 * generated serial version uid
	 */
	private static final long serialVersionUID = 5555878598826046746L;


	private Boolean isJREClass;
	

	private Set<JavaSource> imports = Collections.emptySet();

	/**
	 * java class name with package
	 */
	private String fullname;

	/**
	 * in case of binary file this flag is true
	 */
	private Boolean isBinaryFile;

	private List<JarArchive> jarArchives = Collections.emptyList();

	/**
	 * Constructor for use with source code: in IMPORTS. In case of import i
	 * know only fullname in first sight.
	 * 
	 * @param fullname
	 */
	public JavaSource(String fullname) {
		super();
		this.fullname = fullname;
		// for imports i know the source code
		this.isBinaryFile = Boolean.TRUE;
	}

	/**
	 * Constructor for use with binary files.
	 */
	public JavaSource(JarArchive archive, String fullname) {
		this.jarArchives.add(archive);
		this.fullname = fullname;
		// for binary i dont know the source code; following code is not needed
		this.isBinaryFile = Boolean.FALSE;
	}

	public Set<JavaSource> getImports() {
		return imports;
	}

	public void addImport(JavaSource imp) {
		this.imports.add(imp);
	}

	public String getFullname() {
		return fullname;
	}

	public void setFullname(String fullname) {
		this.fullname = fullname;
	}

	public Boolean getIsBinaryFile() {
		if (isBinaryFile == null) {
			throw new NullPointerException("Flag binary file was not set!");
		}
		return isBinaryFile;
	}

	public void setIsBinaryFile(Boolean isBinaryFile) {
		this.isBinaryFile = isBinaryFile;
	}

	public List<JarArchive> getJarArchives() {
		return jarArchives;
	}

	public void addJarArchive(JarArchive jarArchive) {
		this.jarArchives.add(jarArchive);
	}

	public String getPackageName() {
		if (fullname == null || "".equals(fullname)) {
			throw new NullPointerException("Class must have (full) name with package!");
		}
		String sp[] = fullname.split("\\.");
		return sp[sp.length - 1];
	}

	public static void main(String[] args) {
		JavaSource s = new JavaSource("com.oracle.driver.DriverImpl");
		System.out.println(s.getPackageName());

	}
	
	public Boolean getIsJREClass() {
		return isJREClass;
	}
	
	public void setIsJREClass(Boolean isJREClass) {
		this.isJREClass = isJREClass;
	}
}
